/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse;

/**
 *
 * @author Swang
 */
public class ExceptionStackTraceElementTest {

    public static void f1() {
        try {
            throw new Exception();
        } catch (Exception e) {
            for (StackTraceElement ste : e.getStackTrace()) {
                System.out.println(ste.toString());
            }
        }
    }

    public static void f2() throws Exception {
        try {
            throw new Exception();
        } catch (Exception e) {
            //throw e;
            throw (Exception) e.fillInStackTrace();
        }
    }

    public static void f3() throws Exception {
        Exception e = new Exception();
        e.initCause(new NullPointerException()); //Caused by: java.lang.NullPointerException
        throw e;
    }

    public static void main(String[] args) {
        //f1();
        try {
            f3();
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }
}
